# Copyright 2023 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//bazel:serving.bzl", "serving_cc_library", "serving_cc_test")

package(default_visibility = ["//visibility:public"])

serving_cc_library(
    name = "source",
    deps = [
        ":dataproxy_source",
        ":filesystem_source",
        ":http_source",
        ":oss_source",
    ],
)

serving_cc_library(
    name = "source_base",
    srcs = ["source.cc"],
    hdrs = ["source.h"],
    deps = [
        "//secretflow_serving/config:model_config_cc_proto",
        "//secretflow_serving/core:exception",
        "//secretflow_serving/util:sys_util",
    ],
)

serving_cc_library(
    name = "factory",
    hdrs = ["factory.h"],
    deps = [
        ":source_base",
        "//secretflow_serving/core:singleton",
    ],
)

serving_cc_library(
    name = "filesystem_source",
    srcs = ["filesystem_source.cc"],
    hdrs = ["filesystem_source.h"],
    deps = [
        ":factory",
    ],
    alwayslink = True,
)

serving_cc_library(
    name = "oss_source",
    srcs = ["oss_source.cc"],
    hdrs = ["oss_source.h"],
    deps = [
        ":factory",
        "//secretflow_serving/util:oss_client",
    ],
    alwayslink = True,
)

serving_cc_library(
    name = "http_source",
    srcs = ["http_source.cc"],
    hdrs = ["http_source.h"],
    deps = [
        ":factory",
        "//secretflow_serving/util:network",
        "//secretflow_serving/util:oss_client",
        "@brpc",
        "@yacl//yacl/utils:elapsed_timer",
    ],
    alwayslink = True,
)

proto_library(
    name = "http_service_proto",
    srcs = [
        "http_service.proto",
    ],
)

cc_proto_library(
    name = "http_service_cc_proto",
    deps = [":http_service_proto"],
)

serving_cc_test(
    name = "http_source_test",
    srcs = ["http_source_test.cc"],
    deps = [
        ":http_service_cc_proto",
        ":http_source",
        "//secretflow_serving/util:sys_util",
    ],
)

serving_cc_library(
    name = "dataproxy_source",
    srcs = ["dataproxy_source.cc"],
    hdrs = ["dataproxy_source.h"],
    deps = [
        ":factory",
        "@dataproxy//dataproxy_sdk:sdk",
    ],
    alwayslink = True,
)

serving_cc_test(
    name = "source_test",
    srcs = ["source_test.cc"],
    deps = [
        ":source",
    ],
)
